//
//  SlideViewController.m
//  功能模块代码
//
//  Created by apple  on 2017/11/27.
//  Copyright © 2017年 JMZ. All rights reserved.
//

#import "SlideViewController.h"
#import "HHSlideView.h"
#import "HTHorizontalSelectionList.h"
#import "MyCollectionViewCell.h"

@interface SlideViewController () <HHSlideViewDelegate,HTHorizontalSelectionListDelegate, HTHorizontalSelectionListDataSource,UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) UIView *projectView;//水印主题视图
@property (nonatomic, strong) NSArray *itemDataArray;
@property (nonatomic, strong) HTHorizontalSelectionList *selectionList;
@property(nonatomic,strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *arrayTest;
@property (nonatomic, strong) NSMutableArray *sorceDataArray;

@end

@implementation SlideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    HHSlideView *slideView = [[HHSlideView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64)];
//    slideView.delegate = self;
//    [self.view addSubview:slideView];
    
    UIImageView *background = [[UIImageView alloc] initWithFrame:self.view.bounds];
    background.image = [UIImage imageNamed:@"background"];
    [self.view addSubview:background];
    
    _projectView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenH - 200, ScreenW, 200)];
    _projectView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_projectView];
    
    self.selectionList = [[HTHorizontalSelectionList alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    self.selectionList.delegate = self;
    self.selectionList.dataSource = self;
    
    [_projectView addSubview:self.selectionList];
    
    self.itemDataArray = [[NSArray alloc] initWithObjects:@"广西云", @"21周年", @"上线啦", @"更多免费拿主题", nil];
    self.sorceDataArray = [NSMutableArray array];
    _arrayTest = [NSMutableArray array];
    for (int i = 0; i < 4; i++) {
        NSMutableArray *array = [NSMutableArray array];
        for (int j = 0; j < 4; j ++) {
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            [dict setValue:[NSString stringWithFormat:@"记者采访%d",i] forKey:@"project"];
            [dict setValue:@"project_image" forKey:@"imageName"];
            [array addObject:dict];
        }
        [_arrayTest addObject:array];
    }
    
    self.sorceDataArray = _arrayTest[0];
    
    _collectionView = ({
        
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
        layout.itemSize = CGSizeMake(80, 80);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.minimumLineSpacing = 20;
        
        UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width,150) collectionViewLayout:layout];
        collectionView.backgroundColor = [UIColor blackColor];
        collectionView.alpha = 0.5;
        collectionView.delegate = self;
        collectionView.dataSource = self;
        collectionView.scrollsToTop = NO;
        collectionView.showsVerticalScrollIndicator = NO;
        collectionView.showsHorizontalScrollIndicator = NO;
        [collectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:kMyCollectionViewCellID];
        [_projectView addSubview:collectionView];
        collectionView;
    });

}

#pragma mark - HHSlideViewDelegate

- (NSInteger)numberOfSlideItemsInSlideView:(HHSlideView *)slideView {
    
    return _itemDataArray.count;
}

- (NSInteger)numberOfSlideItemsOneLineInSlideView:(HHSlideView *)slideView {
    
    return 3;
}

- (NSArray *)namesOfSlideItemsInSlideView:(HHSlideView *)slideView {
    
//    NSArray *dataArray = [[NSArray alloc] initWithObjects:@"广西云", @"21周年", @"上线啦", @"更多免费拿主题", nil];
    return _itemDataArray;
}

- (void)slideView:(HHSlideView *)slideView didSelectItemAtIndex:(NSInteger)index {
    
    
    NSLog(@" index %li", index);
}

- (NSArray *)childViewControllersInSlideView:(HHSlideView *)slideView {
    
    return nil;
}

- (UIColor *)colorOfSlideView:(HHSlideView *)slideView {
    
    return [UIColor clearColor];
    
}

- (UIColor *)colorOfSliderInSlideView:(HHSlideView *)slideView {
    
    //    return [UIColor getColor:@"#90d7ec"];
//    return [UIColor colorWithRed:0.31 green:0.95 blue:0.71 alpha:1];
    return [UIColor clearColor];
}

#pragma mark - HTHorizontalSelectionListDataSource Protocol Methods

- (NSInteger)numberOfItemsInSelectionList:(HTHorizontalSelectionList *)selectionList {
    return self.itemDataArray.count;
}

- (NSString *)selectionList:(HTHorizontalSelectionList *)selectionList titleForItemWithIndex:(NSInteger)index {
    return self.itemDataArray[index];
}

#pragma mark - HTHorizontalSelectionListDelegate Protocol Methods

- (void)selectionList:(HTHorizontalSelectionList *)selectionList didSelectButtonWithIndex:(NSInteger)index {
    // update the view for the corresponding index
    NSLog(@"--->选择了：%@",self.itemDataArray[index]);
    self.sorceDataArray = _arrayTest[index];
    [_collectionView reloadData];
}

#pragma mark - UICollectionViewDataSource
//设置最小行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 20.f;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _sorceDataArray.count;
}


- ( UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kMyCollectionViewCellID forIndexPath:indexPath];
    
    NSDictionary *dict = _sorceDataArray[indexPath.row];
    
    cell.projectTitle.text = dict[@"project"];
    cell.imageView.image = [UIImage imageNamed:dict[@"imageName"]];
    
    return cell;
}

#pragma mark - UICollectionViewDelegateFlowLayout
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
    
//    NSDictionary *dict = _sorceDataArray[indexPath.row];
    
//    [(MyCollectionViewCell *)cell configureCellWithPostURL:dict[param_pigUrl]];
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
